package com.quectel.core.module.dept.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.quectel.core.module.dept.entity.DeptEntity;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author caolu
 * @email louis.cao@quectel.com
 * @date 2022/03/24 10:07
 */

public interface DeptDao extends BaseMapper<DeptEntity> {
    /**
     * 查询列表
     *
     * @param params
     * @return
     */
    List<DeptEntity> queryList(Map<String, Object> params);

    /**
     * 查询数量
     *
     * @param params
     * @return
     */
    int queryTotal(Map<String, Object> params);

    @Select("<script> with recursive cte as\n" +
            "(\n" +
            "select * from dept where id = #{deptId}\n" +
            "union all\n" +
            "select d.* from dept d INNER JOIN cte c on d.parent_id = c.id\n" +
            ")\n" +
            "select * from cte\n" +
            "</script>")
    List<DeptEntity> queryByRecursion(Long deptId);
}
